//
//  CZAcquireAuthCodeButton.m
//  School
//
//  Created by senxin on 14/12/24.
//  Copyright (c) 2014年 j. All rights reserved.
//

#import "DBAcquireAuthCodeButton.h"
#import "Header.h"
#import "UIColor+NN.h"

#define k_button_timer_number 90
//#define k_message_user_acquire_auth_code @"获取验证码"
#define k_message_user_acquire_auth_code kLangForAlert(@"Receive verification code", @"获取验证码")

@interface DBAcquireAuthCodeButton ()
{
    NSTimer *cTimer;
    NSInteger iTimerCount;
}
@end

@implementation DBAcquireAuthCodeButton


//- (void)initButton
//{
//    iTimerCount = k_button_timer_number;
//    self.userInteractionEnabled = YES;
//    
//}

- (void)tarStartButtonTimer
{
    // 开始计时通知
    if (self.DBdelte) {
        [self.DBdelte DBAcquireAuthCodeButtonStart:self];
    }
    iTimerCount = 59;
    self.userInteractionEnabled = NO;
    cTimer = [NSTimer scheduledTimerWithTimeInterval:1.2f target:self selector:@selector(didButtonTimerRefresh) userInfo:nil repeats:YES];
}
- (void)tarStopButtonTimer
{
    [cTimer invalidate];
//    [self setTitleColor:MAIN_COLOR_Blue forState:UIControlStateNormal];
//    [self setTitleColor:MAIN_COLOR_Blue forState:UIControlStateHighlighted];
//    [self setTitle:k_message_user_acquire_auth_code  forState:UIControlStateNormal];
//    [self setTitle:k_message_user_acquire_auth_code  forState:UIControlStateHighlighted];
    self.userInteractionEnabled = YES;
    iTimerCount = k_button_timer_number;
    // 开始计时通知
    if (self.DBdelte) {
        [self.DBdelte DBAcquireAuthCodeButtonStop:self];
    }
}

- (void)didButtonTimerRefresh
{
//    NSLog(@"iTimerCount===%ld",iTimerCount);
   
    self.titleLabel.text = [NSString stringWithFormat:@"%lds",(long)iTimerCount];
    [self setTitle:[NSString stringWithFormat:@"%lds",(long)iTimerCount]  forState:UIControlStateNormal];
    [self setTitle:[NSString stringWithFormat:@"%lds",(long)iTimerCount]  forState:UIControlStateHighlighted];
     iTimerCount --;
    if (iTimerCount == 0) {
        [self tarStopButtonTimer];
    }
}

@end
